import Vue from 'vue';

import App from './App.vue';
import router from './router';
import store from './store/index'; // 本地缓存
import baiduPush from './utils/baiduStatistics'; // 百度统计

// 引入全部样式
import 'vant/lib/index.css';
import 'vant/lib/icon/local.css'; //引用本地字体css
import 'amfe-flexible';
// eslint-disable-next-line
_hmt.push([
	'_requirePlugin',
	'UrlChangeTracker',
	{
		shouldTrackUrlChange: function(newPath, oldPath) {
			return newPath && oldPath;
		}
	}
]);

// 引入工具类
import './utils/vantUI';
import './utils/mock';
import './utils/globalFn'; // 全局方法
import './utils/directive'; // 全局指令
import './utils/globalFilter'; // 全局过滤器
import './utils/service'; // 接口服务
import './utils/iconfont'; // 图标
import '@/filters'; // 图标

// 全局注入
import { Lazyload } from 'vant';
Vue.use(Lazyload, {
	lazyComponent: true,
	loading: require('@/assets/images/common/loading.png'),
	error: require('@/assets/images/common/error.png'),
	filter: {
		webp(listener, options) {
			if (!options.supportWebp) return;
			if (/goods-detail/.test(window.location.href)) {
				if (navigator.userAgent.toLowerCase().indexOf('iphone') == -1) {
					listener.src += '_600x600_.webp';
					return;
				}
				listener.src += '_600x600.jpg';
				return;
			}
			const isCDN = /alicdn.com/;
			if (isCDN.test(listener.src)) {
				if (navigator.userAgent.toLowerCase().indexOf('iphone') == -1) {
					listener.src += '_200x200_.webp';
					return;
				}
				listener.src += '_200x200.jpg';
			}
		}
	}
});

// 统计
Vue.prototype.$hmt = {
	push(action, desc = '') {
		console.log('百度统计', action, desc);
		// #ifdef H5
		_hmt.push(['_trackEvent', '百亿补贴', action, desc]);
		// #endif
	}
};

// Vue.prototype.$selfUrl = 'http://192.168.0.158:8085';
// Vue.prototype.$selfUrl = 'http://debug.laigemao.com';
// Vue.prototype.$selfUrl = 'https://mall.xmonecode.com';
// Vue.prototype.$selfUrl = 'http://localmiao.hk.utools.club';
switch (process.env.NODE_ENV) {
	case 'production':
		Vue.prototype.$selfUrl = 'https://mall.xmonecode.com';
		// Vue.prototype.$selfUrl = 'http://localmiao.hk.utools.club';
		break;
	default:
		Vue.prototype.$selfUrl = 'http://localmiao.cn1.utools.club';
}

Vue.config.productionTip = false;
Vue.prototype.$baiduPush = baiduPush;
new Vue({
	router,
	store,
	render: h => h(App)
}).$mount('#app');
